<?php if (!defined('THINK_PATH')) exit();?><style>
	.userform{
		padding:15px 10px 15px 10px;
	}
	.viewform input{
		width:200px;
	}
	.tips{
		color:#777777;
	}
</style>
<table id="dg_user"></table>
<div id="tool_user">
	<table>
		<tr>
			<td>
				<a href="#" class="easyui-linkbutton" id="bt_show_add_user" data-options="iconCls:'icon-standard-folder-page',plain:true">添加</a>
				<a href="#" class="easyui-linkbutton" id="bt_dele_user" data-options="iconCls:'icon-standard-page-white-delete',plain:true">删除</a>
				<a href="#" class="easyui-linkbutton" id="bt_show_edit_user" data-options="iconCls:'icon-standard-application-edit',plain:true">编辑</a>
			</td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td>
				<a href="#" class="easyui-linkbutton" id="bt_view_user" data-options="iconCls:'icon-standard-application-view-gallery',plain:true">查看</a>
			</td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td>
				<a href="#" class="easyui-linkbutton" id="bt_reload_user" data-options="iconCls:'icon-standard-arrow-refresh',plain:true">刷新</a>
			</td>
			<td>
			</td>
		</tr>
	</table>
</div>
<div id="view_user" class="easyui-dialog" style="width:314px;height:387px;padding:10px;overflow:hidden;" title="&nbsp;&nbsp;查看用户信息" data-options="iconCls:'icon-standard-folder-page',buttons:'#dlg_view_user',closed:true,resizable:false,modal:true,closable:true">
	<form id="view_form_user" method="post">
		<table class="userform">
			<tr>
				<th>用户ID:</th>
				<td>				
					<input id="id" name="id" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>
				</td>
			</tr>
			<tr>				
				<th>用户名:</th>
				<td>					
					<input id="username" name="username" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>				
				<th>昵称:</th>
				<td>					
					<input id="nickname" name="nickname" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>				
				<th>用户组:</th>
				<td>					
					<input id="groupid" name="group_id" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>
				<th>E-Mail:</th>
				<td>
					
					<input id="email" name="email" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>
				<th>登录次数:</th>
				<td>				
					<input id="login_num" name="login_num" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>
				<th>创建时间:</th>
				<td>				
					<input id="creattime" name="creattime" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>
				<th>修改时间:</th>
				<td>					
					<input id="moditime" name="moditime" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>
				<th>上次登录时间:</th>
				<td>					
					<input id="last_login_time" name="last_login_time" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>
				<th>状态:</th>
				<td>					
					<input id="status" name="status" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>
			<tr>
				<th>登录IP:</th>
				<td>					
					<input id="login_ip" name="login_ip" class="easyui-textbox" type="text" disabled="disabled" style="width:160px;"/>	
				</td>
			</tr>

		</table>
	</form>
</div>
<div id="dlg_view_user">
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="javascript:$('#view_user').dialog('close')">确认</a>
</div>

<!-- 编辑 -->
<div id="edit1_user" class="easyui-dialog" style="width: 436px; height:324px;padding:10px;overflow:hidden;" title="&nbsp;&nbsp;编辑角色" data-options="iconCls:'icon-standard-folder-page',buttons:'#dlg_edit_user',closed:true,resizable:false,modal:true,closable:true">
	<form id="edit_form_user" method="post">
		<input type="hidden" id="id" name="id" type="text"/>
		<table class="userform">


<tr>
				<th>用户名：</th>
				<td>
					<input id="username" name="username" type="text" class="easyui-textbox tips" data-options="required:true,editable:false" style="width:300px;"/> 
				</td>
			</tr>
			<tr>
				<td>
					
				</td>
				<td class="tips">
					（用户名不能修改！） 
				</td>
			</tr>
			<tr>
				<th>昵称</th>
				<td>
					<input id="nickname" name="nickname" type="text" class="easyui-textbox" data-options="required:true,prompt:'请输入真实姓名作为昵称'" style="width:300px;"/> 
				</td>
			</tr>
			<tr>
				<th>用户组：</th>
				<td>
					<!-- <input id="group_id" class="easyui-combobox" name="group_id"   
    data-options="valueField:'group_id',textField:'text',url:'/solve/index.php/Admin/User/usergrouplist',editable:false,required:true,panelHeight:'auto',multiple:true," style="width:120px;"/> --> 
<input id="classifyb" class="easyui-combogrid" name="classify[]"   
    data-options="idField:'id',textField:'title',url:'/solve/index.php/Admin/User/authgrouplist',editable:false,required:true,panelHeight:'auto',multiple:true,panelWidth:350,
	 columns:[[    
                {field:'id', checkbox: true},    
                {field:'title',title:'用户组',width:100},    
                {field:'describtion',title:'描述',width:220}   
            ]]" style="width:300px;"/>
	</td>
			</tr>
			<tr>
				<th>E-Mail：</th>
				<td>

					<input id="email" name="email" type="text" class="easyui-textbox" data-options="required:true,validType:'email'" style="width:300px;"/>

				</td>
			</tr>

			<tr>
				<th>状态：</th>
				<td>
					<select id="status" class="easyui-combobox" name="status" data-options="editable:false,panelHeight:'auto'" style="width:300px;"> 
						<option value="1">开启</option>
						<option value="0">关闭</option>
					</select>
				</td>
			</tr>
			<tr>
				<th>密码：</th>
				<td>

					<input  id="passwordb" name="password" type="password" class="easyui-textbox"  style="width:300px;"/>   
				</td>
			</tr>
			<tr>
				<td>
					
				</td>
				<td class="tips">
					（密码留空则表示不进行更改！） 
				</td>
			</tr>
			<tr>
				<th>确认密码：</th>
				<td>
					<input  id="repassword" name="repassword" type="password" class="easyui-textbox"     
 validType="equals['#passwordb']" style="width:300px;"/>
				</td>
				
			</tr>
			<tr>
				<td>
					
				</td>
				<td class="tips">
				</td>
			</tr>





		</table>
	</form>
</div>
<div id="dlg_edit_user">
	<a href="#" id="bt_edit_user" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确认</a>
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#edit1_user').dialog('close')">取消</a>
</div>
<!--添加窗口 -->
<div id="add_user" class="easyui-dialog" style="width: 436px; height:304px; padding: 10px; overflow: hidden;" title="&nbsp;&nbsp;添加用户" data-options="iconCls:'icon-standard-folder-page',buttons:'#dlg_add_user',closed:true,resizable:false,modal:true,closable:true">
	<form id="add_form_user" method="post">
		<table class="userform">
			<tr>
				<th>用户名：</th>
				<td>
					<input id="username" name="username" type="text" class="easyui-textbox" data-options="required:true,prompt:'请输入5位保险编号作为用户名'" style="width:300px;"/> 
				</td>
			</tr>
			<tr>
				<th>昵称</th>
				<td>
					<input id="nickname" name="nickname" type="text" class="easyui-textbox" data-options="required:true,prompt:'请输入真实姓名作为昵称'" style="width:300px;"/> 
				</td>
			</tr>
			<tr>
				<th>用户组：</th>
				<td>
					<!-- <input id="group_id" class="easyui-combobox" name="group_id"   
    data-options="valueField:'group_id',textField:'text',url:'/solve/index.php/Admin/User/usergrouplist',editable:false,required:true,panelHeight:'auto',multiple:true," style="width:120px;"/> --> 
<input id="classify" class="easyui-combogrid" name="classify[]"   
    data-options="idField:'id',textField:'title',url:'/solve/index.php/Admin/User/authgrouplist',editable:false,required:true,panelHeight:'auto',multiple:true,panelWidth:350,
	 columns:[[    
                {field:'id', checkbox: true},    
                {field:'title',title:'用户组',width:100},    
                {field:'describtion',title:'描述',width:220}   
            ]]" style="width:300px;"/>
	</td>
			</tr>
			<tr>
				<th>E-Mail：</th>
				<td>

					<input id="email" name="email" type="text" class="easyui-textbox" data-options="required:true,validType:'email'" style="width:300px;"/>

				</td>
			</tr>

			<tr>
				<th>状态：</th>
				<td>
					<select id="status" class="easyui-combobox" name="status" data-options="editable:false,panelHeight:'auto'" style="width:300px;"> 
						<option value="1">开启</option>
						<option value="0">关闭</option>
					</select>
				</td>
			</tr>
			<tr>
				<th>密码：</th>
				<td>

					<input  id="passworda" name="password" type="password" class="easyui-textbox" data-options="required:true" style="width:300px;"/>    
				</td>
			</tr>
			<tr>
				<th>确认密码：</th>
				<td>
					<input  id="repassword" name="repassword" type="password" class="easyui-textbox"     
    required="required" validType="equals['#passworda']" style="width:300px;"/> 
				</td>
			</tr>
		</table>
	</form>
</div>
<div id="dlg_add_user">
	<a href="#" class="easyui-linkbutton" id="bt_add_user" data-options="iconCls:'icon-ok'">确认</a>
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#add_user').dialog('close')">取消</a>
</div>
<script>
$(function(){
			$.extend($.fn.validatebox.defaults.rules, {    
    equals: {    
        validator: function(value,param){    
            return value == $(param[0]).val();    
        },    
        message: '两次输入的密码不符！'   
    }    
}); 

		});

	$('#dg_user').datagrid({
	url: '/solve/index.php/Admin/user/userlist',
	toolbar: '#tool_user',
	pagination: true,
	fit: true,
	width: function() {
		return document.body.clientWidth * 0.9
	},
	nowrap: false,
	collapsible: true,
	fitColumns: true,
	autoRowHeight: true,
	striped: true, //交替行
	singleSelect: true, //只允许选择一行
	rownumbers: true,
	border: false,
	sortName: 'id',
	sortOrder: 'desc', //倒序排列
	remoteSort: false,
	pageSize: 50,
	pageList: [10, 15, 20, 40, 50, 100, 200],
	columns: [
		[{
				field: 'id',
				checkbox: true
			},

			{
				field: 'username',
				title: '用户名',
				width: 100
			},
			

			{
				field: 'nickname',
				title: '昵称',
				width: 100
			}, {
				field: 'classify',
				title: '用户组',
				width: 100,
				formatter: function(value,row,index) {
					if(value.length>0){
						var str="";
						for(var i=0;i<value.length;i++){
							if(i==value.length-1){
								str=str+value[i].title;
							}else{
								str=str+value[i].title+'，';
							}
							
						}
						return str;
				}else{
					return "";
				}
					
							
				}
					
			
			}, {
				field: 'email',
				title: 'E-Mail',
				width: 200,
				align: 'left'
			}, {
				field: 'login_num',
				title: '登录次数',
				width: 100,
				align: 'left'
			}, {
				field: 'creattime',
				title: '创建时间',
				width: 200,
				align: 'left'
			}, {
				field: 'last_login_time',
				title: '最后登录时间',
				width: 200,
				align: 'left'
			}, {
				field: 'login_ip',
				title: '最后登录ip',
				width: 200,
				align: 'left'
			}, {
				field: 'status',
				title: '状态',
				width: 50,
				align: 'left'
			}
		]
	]
});
Date.prototype.Format = function(fmt) { //author: meizz 
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"h+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}

//打开添加窗口

$('#bt_show_add_user').click(
	function() {
		var myDate = new Date();
		var date;
		date = new Date(new Date()).Format("yyyy-MM-dd");
		$('#add_user').window('open'); // open a window 
		$('#add_form_user').form('load', {
			group_id: '1',
			username: '',
			email: '',
			status: '1',
			password: '',
			repassword: ''
		});

		/* 				$('#add_form_user').form('clear'); */
	}
)

	//刷新
$('#bt_reload_user').click(
		function() {
			$('#dg_user').datagrid('reload');
		}
	)
	//添加	
$('#bt_add_user').click(
	function() {

		$('#add_form_user').form('submit', {
			url: '/solve/index.php/Admin/User/adduser',
			success: function(data) {
				$("#dg_user").datagrid("reload");
				$.messager.alert('添加用户', data, 'info');
				$('#add_user').dialog('close')

			}
		});

	}
)
//删除

$('#bt_dele_user').click(
	function() {

		var row = $('#dg_user').datagrid("getSelected");


		if (row) {
			$.messager.confirm('确认', '您确定要删除此角色吗?', function(r) {
				if (r) {
					$.post('/solve/index.php/Admin/User/deleteUser', {
						id: row.id
					}, function(data) {
						if (data.status==1) {
							$('#dg_user').datagrid('reload'); // reload the user data  
							$.messager.alert('删除用户', data.data, 'info');
						} else {
							$.messager.show({ // show error message  
								title: '错误',
								msg: data.data

							});

						}
					}, 'json');
				}
			});
		} else {
			$.messager.alert("请选择", "请选择要删除的项目！", "info");
		}



	}
)

//编辑窗口
$('#bt_show_edit_user').click(
	function() {
		var row = $('#dg_user').datagrid("getSelected");
		if(row){
			$("#edit1_user").dialog("open").dialog('setTitle', '&nbsp;&nbsp;编辑用户');	
			row.password="";
			
			if(row.classify.length>0){
				var str='';
				for(var i=0;i<row.classify.length;i++){
					if(i!=row.classify.length-1){
						str=str+row.classify[i].id+',';
					}else{
						str=str+row.classify[i].id;
					}				
				}
				
			}else{
				str='';
			}
			$("#edit_form_user").form("load", row);
			$('#classifyb').combogrid('setValue', row.classify);


			} else {
				$.messager.alert("请选择要编辑的行", "请选择要编辑的行！", "info");
			}

		}
	)

//编辑
$('#bt_edit_user').click(
	function() {
		$('#edit_form_user').form('submit', {
			url: '/solve/index.php/Admin/User/modifyUser',
			
			success: function(data) {
				var data = eval('(' + data + ')');
				if(data.status==1){
				$("#dg_user").datagrid("reload");
				$.messager.alert('编辑项目', data.data, 'info');
				$('#edit1_user').dialog('close')
				}else{
                    $("#dg_user").datagrid("reload");
                    $.messager.alert('编辑项目', data.data, 'info');
                    $('#edit1_user').dialog('close')
				}
				
			}
		});
	}
)


$('#bt_view_user').click(
	function() {
		var row = $('#dg_user').datagrid("getSelected");
		if(row){
			$("#view_user").dialog("open").dialog('setTitle', '&nbsp;&nbsp;编辑用户');	
			row.password="";
			var str='';
			console.log(row.classify);
			if(row.classify.length>0){
				
				for(var i=0;i<row.classify.length;i++){
					if(i!=row.classify.length-1){
						str=str+row.classify[i].title+',';
					}else{
						str=str+row.classify[i].title;
					}				
				}
				
			}else{
				str='';
			}
			$("#view_form_user").form("load", row);
			// $('#classifyb').combogrid('setValue', row.classify);
			$('#groupid').textbox('setValue',str);	


			} else {
				$.messager.alert("请选择要编辑的行", "请选择要编辑的行！", "info");
			}
	}
)
</script>